package com.ktgj.train.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.train.domain.TrainOrderOperation;
import com.ktgj.train.service.ITrainOrderOperationService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 操作记录Controller
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@ControllerAdvice
@RestController
@RequestMapping("/operation")
public class TrainOrderOperationController extends BaseController
{
    @Autowired
    private ITrainOrderOperationService trainOrderOperationService;

    /**
     * 查询操作记录列表
     */
    @PreAuthorize(hasPermi = "train:operation:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainOrderOperation trainOrderOperation)
    {
        startPage();
        List<TrainOrderOperation> list = trainOrderOperationService.selectTrainOrderOperationList(trainOrderOperation);
        return getDataTable(list);
    }

    /**
     * 导出操作记录列表
     */
    @PreAuthorize(hasPermi = "train:operation:export")
    @Log(title = "操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainOrderOperation trainOrderOperation) throws IOException
    {
        List<TrainOrderOperation> list = trainOrderOperationService.selectTrainOrderOperationList(trainOrderOperation);
        ExcelUtil<TrainOrderOperation> util = new ExcelUtil<TrainOrderOperation>(TrainOrderOperation.class);
        util.exportExcel(response, list, "操作记录数据");
    }

    /**
     * 获取操作记录详细信息
     */
    @PreAuthorize(hasPermi = "train:operation:query")
    @GetMapping(value = "/{operationid}")
    public AjaxResult getInfo(@PathVariable("operationid") Long operationid)
    {
        return AjaxResult.success(trainOrderOperationService.selectTrainOrderOperationById(operationid));
    }

    /**
     * 新增操作记录
     */
    @PreAuthorize(hasPermi = "train:operation:add")
    @Log(title = "操作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainOrderOperation trainOrderOperation)
    {
        return toAjax(trainOrderOperationService.insertTrainOrderOperation(trainOrderOperation));
    }

    /**
     * 修改操作记录
     */
    @PreAuthorize(hasPermi = "train:operation:edit")
    @Log(title = "操作记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainOrderOperation trainOrderOperation)
    {
        return toAjax(trainOrderOperationService.updateTrainOrderOperation(trainOrderOperation));
    }

    /**
     * 删除操作记录
     */
    @PreAuthorize(hasPermi = "train:operation:remove")
    @Log(title = "操作记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operationids}")
    public AjaxResult remove(@PathVariable Long[] operationids)
    {
        return toAjax(trainOrderOperationService.deleteTrainOrderOperationByIds(operationids));
    }
}
